#ifndef SCREENVIEWER_H
#define SCREENVIEWER_H

#include <QObject>
#include <QUdpSocket>
#include <QLabel>
#include <QPixmap>

class ScreenViewer : public QObject
{
    Q_OBJECT

public:
    explicit ScreenViewer(QObject *parent = nullptr);
    ~ScreenViewer();

    // 核心功能
    bool initialize();
    void startListening(int port = 5006);
    void stopListening();
    bool isListening() const;

    // 设置显示组件
    void setDisplayLabel(QLabel* label);

signals:
    void listeningStarted();
    void listeningStopped();
    void screenReceived(const QPixmap& screen);
    void errorOccurred(const QString& error);

private slots:
    void onReadyRead();
    void onSocketError(QAbstractSocket::SocketError error);

private:
    QUdpSocket* udpSocket;
    QLabel* displayLabel;
    bool isListeningFlag;
    int frameCounter;
};

#endif // SCREENVIEWER_H
